from flask import Flask
from flask import render_template, request, redirect, url_for

from test_bp import bp

app = Flask(__name__)

app.register_blueprint(bp, url_prefix='/bp')

@app.route('/hello')
def hello_world():
    return '<h1>Hello World111!</h1>'


@app.route('/python/')
def hello_python():
    return 'Hello Python!'


@app.route('/hello/<name>')
def hello_name(name):
    if name == 'python':
        return redirect(url_for('hello_python'))
    else:
        return redirect(url_for('hello_world'))


@app.route('/login')
def login():
    return render_template('log_in.html')

@app.route('/center/add', methods=['GET','POST'])
def center_add():
    if request.method == 'GET':
        name = request.args.get('name')
        age = request.args.get('age')
        hobby = request.args.getlist('hobby')
        
        print(hobby)
        return '<h1>name:{}</h1><br/><h2>age:{}</h2><br/> hobby:{}'.format(name,age,','.join(hobby))
    if request.method == 'POST':
        name = request.form.get('name')
        age = request.form.get('age')
        hobby = request.form.getlist('hobby')
        print(hobby)
        return 'name:{},age:{},hobby:{}'.format(name,age,','.join(hobby))


if __name__ == "__main__":
    app.run(host='0.0.0.0',port=5050)